using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CooldownState : IState
{
    private Enemy enemy;
    private float cooldownTimer;

    public CooldownState(Enemy enemy)
    {
        this.enemy = enemy;
        this.cooldownTimer = enemy.parameters.enemyAttackCooldown;
    }

    public void OnEnter()
    {
        cooldownTimer = enemy.parameters.enemyAttackCooldown;
        enemy.parameters.enemyAnimator.Play("Chase"); // 冷却期间播放追击动画
    }

    public void OnFixedUpdate()
    {
        throw new System.NotImplementedException();
    }

    public void OnUpdate()
    {
        cooldownTimer -= Time.deltaTime;
        if (cooldownTimer <= 0)
        {
            // 冷却结束，检查是否在攻击范围内
            float distance = Vector2.Distance(enemy.transform.position, enemy.target.position);
            if (distance < enemy.parameters.enemyAttackDistance)
            {
                enemy.TransitionState(StateType.Attack);
            }
            else
            {
                enemy.TransitionState(StateType.Chase);
            }
        }
    }

    public void OnExit()
    {
        // 在退出冷却状态时重置追击动画
        
    }
}




